home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 5.4 KB | 192 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLMemSin.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWODEXCE_H
- #include "FWODExce.h"
- #endif
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #define VARIABLE_MACROS
- #define FW_OMemorySink_Class_Source
- #include "SLMemSin.xih"
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWStream
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinkInit
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OMemorySink__InitFromBuffer(FW_OMemorySink *somSelf, Environment *ev,
- void* buffer,
- long capacity,
- long length)
- {
- FW_UNUSED(ev);
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- _fBuffer = (char*)buffer;
- _fCapacity = capacity;
- _fLength = length;
- _fPosition = 0;
-
- FW_ASSERT(_fLength <= _fCapacity);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinkRead
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OMemorySink__Read(FW_OMemorySink *somSelf, Environment *ev,
- void* destination,
- long count)
- {
- FW_UNUSED(ev);
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- FW_ASSERT(count >= 0);
- FW_ASSERT(_fPosition + count <= _fLength);
-
- FW_PrimitiveCopyMemory(_fBuffer + _fPosition, destination, count);
- _fPosition += count;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinkGetWritableBytes
- //----------------------------------------------------------------------------------------
-
- SOM_Scope long SOMLINK FW_OMemorySink__GetWritableBytes(FW_OMemorySink *somSelf, Environment *ev)
- {
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- return _fCapacity - somSelf->GetPosition(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinkWrite
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OMemorySink__Write(FW_OMemorySink *somSelf, Environment *ev,
- void* source,
- long count)
- {
- FW_UNUSED(ev);
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- FW_ASSERT(count >= 0);
- FW_ASSERT(_fPosition + count <= _fCapacity);
-
- FW_PrimitiveCopyMemory(source, _fBuffer + _fPosition, count);
- _fPosition += count;
- if (_fLength < _fPosition)
- _fLength = _fPosition;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinkGetLength
- //----------------------------------------------------------------------------------------
-
- SOM_Scope long SOMLINK FW_OMemorySink__GetLength(FW_OMemorySink *somSelf, Environment *ev)
- {
- FW_UNUSED(ev);
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- return _fLength;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinkSetLength
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OMemorySink__SetLength(FW_OMemorySink *somSelf, Environment *ev,
- long length)
- {
- FW_UNUSED(ev);
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- FW_ASSERT(length <= _fCapacity);
- _fLength = length;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinkGetPosition
- //----------------------------------------------------------------------------------------
-
- SOM_Scope long SOMLINK FW_OMemorySink__GetPosition(FW_OMemorySink *somSelf, Environment *ev)
- {
- FW_UNUSED(ev);
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- return _fPosition;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinkSetPosition
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OMemorySink__SetPosition(FW_OMemorySink *somSelf, Environment *ev,
- long position)
- {
- FW_UNUSED(ev);
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- FW_ASSERT(position >= 0);
- FW_ASSERT(position <= _fLength);
- _fPosition = position;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinksomInit
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OMemorySink__somInit(FW_OMemorySink *somSelf)
- {
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- FW_OMemorySink_parent_FW_ORandomAccessSink_somInit(somSelf);
-
- _fBuffer = 0;
- _fCapacity = 0;
- _fLength = 0;
- _fPosition = 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OMemorySinksomUninit
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OMemorySink__somUninit(FW_OMemorySink *somSelf)
- {
- FW_OMemorySinkData *somThis = FW_OMemorySinkGetData(somSelf);
-
- FW_OMemorySink_parent_FW_ORandomAccessSink_somUninit(somSelf);
- }
-
-
-